<style scoped>
.preview_image_popup{max-width: 100%;width: 100%;height: 100%;}
</style>
<template>
  <van-popup class="preview_image_popup" v-model:show="is_show" style="background: none;">
    <div class="flex" style="width: 100%;height: 100%;" @click="hide">
      <img-referrer :src="url" style="width: 100%;" draggable="false"/>
    </div>
  </van-popup>
</template>

<script>
import {_href, s94_event} from "@/js/s94_tool.js";
import {reactive} from "vue";
import ImgReferrer from "@/components/widget/ImgReferrer.vue";


const _this = reactive({
  is_show: false,
})

export function preview_img(mode){

  _this.is_show = true;
}
preview_img._this = _this;
preview_img.hide = function(){
  _this.is_show = false;
}

s94_event('router.after', ()=>{
  _this.is_show = false;
})

export default {
  components: {ImgReferrer},
  props: [],
  emits: [],
  data(){
    return {
      is_show: false,
      callback(ac){},

      url: '',
      cart_count: 0,
    }
  },
  methods: {
    show(config, callback){
      this.is_show = true;
      if (typeof config !== 'object') config = {};
      if (typeof callback === 'function') this.callback = callback;

      this.url = _href(config.url);
      this.is_show = !!this.url;
      return this;
    },
    hide(){
      this.is_show = false;
    },
    init(){
      this.hide();
    },

    click(ac){
      if (typeof this.callback !== 'function') return;
      this.callback(this, ac);
    }
  },
  watch: {
  },
  computed: {},
  mounted() {
  }
}
</script>